import { reactive, ref } from 'vue'
export function usePagination(loadData: ()=>Promise<any>,initalPageSize:number=10) {
  const totals = ref<number>(0)
  const pageInfo = reactive({
    page: 1,
    pageSize: initalPageSize,
  })

  const handleSizeChange = (val: number) => {
    pageInfo.pageSize = val
    loadData()
  }

  const handleCurrentChange = (val: number) => {
    pageInfo.page = val
    loadData()
  }

  const resetPagination = () => {
    pageInfo.page = 1
    pageInfo.pageSize=  initalPageSize
  }

  const setTools = (all:number)=>{
    totals.value=all
  }

  return {
    pageInfo,
    handleSizeChange,
    handleCurrentChange,
    resetPagination,
    setTools,
    totals
  }
}